package com.qianguo.shop.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.LinearLayout;

/**
 * @author eva
 * @date 15/11/30
 */
public class ResizableLinearLayout extends LinearLayout {

    public interface OnSizeChangedListener {

        void onSizeChanged(int w, int h, int oldw, int oldh, int dw, int dh);
    }

    private OnSizeChangedListener mSizeChangedListener = null;

    public ResizableLinearLayout(Context context) {
        super(context);
    }

    public ResizableLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ResizableLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public ResizableLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void setOnSizeChangedListener(OnSizeChangedListener listener) {
        mSizeChangedListener = listener;
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if (oldw != 0 || oldh != 0) {
            if (mSizeChangedListener != null) {
                mSizeChangedListener.onSizeChanged(w, h , oldw, oldh, w - oldw, h - oldh);
            }
        }
    }
}
